package lpg;

import java.util.ArrayList;
import java.util.List;

class ActionFileSymbol extends Symbol
{
    ActionFileSymbol(String name, int poolIndex)
    {
        super(name, poolIndex);
        //TODO
        /*
        file = fopen(name_, "wb");
        if ((! file) && strlen(name) > 0)
        {
             cout << "Unable to open file \"" << name_ << "\"\n";
             cout.flush();
             throw 12;
        }
        */
    }

    void flush()
    {
        /* TODO
        if (file) // not the null file?
        {
            initial_headers.Flush(file);
            {
                for (int i = 0; i < headers.Length(); i++)
                    headers[i].Flush(file);
            }
            body.Flush(file);
            {
                for (int i = 0; i < trailers.Length(); i++)
                    trailers[i].Flush(file);
            }
            final_trailers.Flush(file);

            fprintf(file, "\n");
            fclose (file);
            file = NULL;
        }

        return;
        */
    }

    void setBlock(BlockSymbol block)
    {
        this.block = block;
    }

    BlockSymbol block()
    {
        return block;
    }

    StringBuilder initialHeadersBuffer()
    {
        return initialHeaders;
    }

    StringBuilder bodyBuffer()
    {
        return body;
    }

    StringBuilder finalTrailersBuffer()
    {
        return finalTrailers;
    }

    StringBuilder getNextHeaderBuffer()
    {
        StringBuilder buffer = new StringBuilder();
        headers.add(buffer);
        return buffer;
    }

    StringBuilder getNextTrailerBuffer()
    {
        StringBuilder buffer = new StringBuilder();
        trailers.add(buffer);
        return buffer;
    }

    private BlockSymbol block = null;
    private StringBuilder initialHeaders = new StringBuilder();
    private StringBuilder body = new StringBuilder();
    private StringBuilder finalTrailers = new StringBuilder();

    List<StringBuilder> headers = new ArrayList<StringBuilder>();
    List<StringBuilder> trailers = new ArrayList<StringBuilder>();

}
